﻿(function (wtm) {
    $('body').on('click', '[rea-label-editlink]', function (value) {
        var url = $(this).attr('rea-label-editlink');
        var title = $(this).text();
        wtm.OpenDialog(url, new Date().getTime(), title);
    });


    $('body').on('click', '[rea-label-viewlink]', function (value) {
        var url = $(this).attr('rea-label-viewlink');
        wtm.basefiled_OpenDropdown($(this), url);
    });

    // 点击后自动选中文本
    $('body').on('click', '[is-auto-select=true]', function (value) {
        $(this).select();
    });

    // 增加修剪功能
    $('body').on('change', '[trim=true]', function (value) {
        $(this).val($(this).val().trim());
    });

    // 增加自动触发搜索功能
    $('body').on('change', '[is-triggersearch=true]', function (value) {
        var $el = $(this);
        wtm.searchbutton_TriggerSearch($el.parents('[search-panel]').find('[issearchbutton]'));
    });

    layui.form.on('select', function (data) {
        var $el = $(data.elem);
        if ($el.attr('is-triggersearch')) {
            wtm.searchbutton_TriggerSearch($el.parents('[search-panel]').find('[issearchbutton]'));
        }
    });




    // 增加自动触发搜索功能 end

    wtm.basefiled_OpenDropdown = function (el, url) {
        $.get(url, function (str, textStatus, request) {
            if (request.getResponseHeader('IsScript') === 'true') {
                eval(str);
            }
            else {
                layui.dropdown.render({
                    show: true,
                    elem: el,
                    content: "<div class='layui-border-blue' style='width:500px;height:300px;background:aliceblue;padding:20px;'>" + str + "</div>"
                });
            }

        });
    };

})(wtm);